#include <cstdio>
#include <memory.h>
#define INF 100000000

int max( int a, int b ) { return ( a > b )?a :b; }

int n, f[ 101 ][ 101 ][ 2 ];
char s[ 101 ];

int check( int x1, int y1, int x2, int y2 )
{
    int i1 = x1, i2 = x2;
    while ( s[ i1 ] == '0' && i1 < y1 ) i1++;
    while ( s[ i2 ] == '0' && i2 < y2 ) i2++;
    if ( y1 - i1 != y2 - i2 ) return y1 - i1 - y2 + i2;
    while ( i1 <= y1 )
    {
        if ( s[ i1 ] != s[ i2 ] ) return s[ i1 ] - s[ i2 ];
        i1++; i2++;
    }
    return 0;
}

int main( )
{
    int i, j, k, flag, ans;
    while ( scanf("%d%s", &n, s) != EOF )
    {
        memset( f, 0, sizeof( 0 ) );
        for ( i = 0; i < n; i++ )
            for ( j = 0; j < n; j++ )
                f[ i ][ j ][ 0 ] = f[ i ][ j ][ 1 ] = -INF;
        for ( i = 0; i < n; i++ )
            f[ i ][ 0 ][ 0 ] = 0;
        for ( i = 1; i < n; i++ )
            for ( j = 1; j <= i; j++ )
                for ( k = 0; k < j; k++ )
                {
                    flag = check( j, i, k, j - 1 );
                    if ( flag < 0 )
                        f[ i ][ j ][ 0 ] = max( f[ i ][ j ][ 0 ], f[ j - 1 ][ k ][ 1 ] + 1 );
                    else if ( flag > 0 )
                        f[ i ][ j ][ 1 ] = max( f[ i ][ j ][ 1 ], f[ j - 1 ][ k ][ 0 ] + 1 );    
                }
        ans = 0;
        for ( i = 1; i < n; i++ )
        {
            ans = max( ans, f[ n - 1 ][ i ][ 0 ] );
            ans = max( ans, f[ n - 1 ][ i ][ 1 ] );
        }
        printf("%d\n", ans);
    }
    return 0;
}
